<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>{$meta_title}</h2>
    </div>
    <form action="{:U('save')}" method="post" class="form-horizontal">
        <div class="form-item">
            <label class="item-label">课程名称<span class="check-tips"></span></label>
            <div class="controls">
                <label class=" input-large">
                    《{$course.title}》
                </label>
            </div>
        </div>

        <div class="form-item">
            <label class="item-label">课时数<span class="check-tips">(需要上多少节课，0表示上所有课程)</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="_class_hour" id="_class_hour" value="0" onchange="feeCount()" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">选择开始上课编号<span class="check-tips"></span></label>
            <div class="controls">
                <select name="class_start_id" id="class_start_id" onchange="feeCount()">
                    <volist name="plan" id="vo">
                        <option value="{$vo.id}_{$i}">{$i}、{$vo.explain}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">第一次上课时间<span class="check-tips"></span></label>
            <div class="controls">
                <input type="text" class="text input-large" id="class_start_time" name="class_start_time" value="{$class_start_time}" >
            </div>
        </div>

        <div class="form-item" style="margin-top: 30px;">
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
        <input type="hidden"  name="rid" value="{$rid}" >
        <input type="hidden"  name="sid" value="{$sid}" >
        <input type="hidden"  name="course_id" value="{$course_id}" >
        <input type="hidden"  name="fee" id="input_fee" value="" >
        <input type="hidden"  name="class_hour" id="input_class_hour" value="" >
    </form>
</block>

<block name="script">
<script type="text/javascript">

    laydate.render({
        elem: '#class_start_time' ,
        type: 'datetime',
        format: 'yyyy-MM-dd HH:mm' //可任意组合
    });

    //费用计算
    function feeCount() {
        var class_hour = $("#_class_hour").val();
        var class_start_id = $("#class_start_id").val();

        $.ajax({
            type: 'POST',
            url: "{:U('ajaxFeeCount')}",
            data: "course_id={$course_id}&class_hour="+class_hour+"&class_start_id="+class_start_id,
            success: function (res) {
                if(res.status==1){
                    $("#fee").html(res.fee);
                    $("#input_fee").val(res.fee);
                    $("#input_class_hour").val(res.class_hour);

                    if(res.class_hour!=class_hour&&class_hour!=0){
                        updateAlert('课时数超出最大课时!');
                    }else{
                        $('#top-alert').find('button').click();
                    }

                }else{
                    updateAlert('服务器繁忙，请重试!');
                    setTimeout(function(){
                        $('#top-alert').find('button').click();
                    },2000);
                }
            }
        });
    } $(function () { feeCount();});


    //导航高亮
    highlight_subnav('{:U('Charge/add')}');
</script>

</block>
